﻿using LigerUi.MVC.BusinessEntity.Employee;
using LigerUi.MVC.DataAccess.CommonTools;
using LigerUi.MVC.DataModel.EntityClasses;
using LigerUi.MVC.DataModel.EntityClasses.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace LigerUi.MVC.DataAccess.Employee
{
    public class Employee : LigerUi.MVC.DataAccess.IEmployee.IEmployee
    {

        public virtual List<PhoneAttributionModel> ReadList(PhoneAttributionModel filter)
        {
            List<PhoneAttribution> listModel = null;
            if (filter == null)
            {
                listModel = CommonService.SelectList<PhoneAttribution>(null);
            }
            else
            {
                Expression<Func<PhoneAttribution, bool>> where = PredicateExtensionses.True<PhoneAttribution>();
                if (!string.IsNullOrWhiteSpace(filter.AreaCode))
                {
                    where = where.And(p => p.AreaCode.Contains(filter.AreaCode));
                }
                listModel = CommonService.SelectList<PhoneAttribution>(where);
            }

            List<PhoneAttributionModel> listData = new List<PhoneAttributionModel>();
            EntityUtil.CloneData<PhoneAttribution, PhoneAttributionModel>(listModel, listData);
            return listData;
        }

        public virtual List<PhoneAttributionModel> ReadList(Starring.Framework.Data.DataOrder order, Starring.Framework.Data.PagingEntity paging, PhoneAttributionModel filter)
        {         

            List<PhoneAttribution> listModel = null;
            if (filter == null)
            {
                listModel = CommonService.ReadList<PhoneAttribution>(order, paging, null);
            }
            else
            {
                Expression<Func<PhoneAttribution, bool>> where = PredicateExtensionses.True<PhoneAttribution>();
                if (!string.IsNullOrWhiteSpace(filter.AreaCode))
                {
                    where = where.And(p => p.AreaCode.Contains(filter.AreaCode));
                }
                listModel = CommonService.ReadList<PhoneAttribution>(order, paging, where);
            }
            List<PhoneAttributionModel> listData = new List<PhoneAttributionModel>();

            EntityUtil.CloneData<PhoneAttribution, PhoneAttributionModel>(listModel, listData);
            return listData;
        }
    }
}
